package leetcode.L45;

class Solution {
    public int jump(int[] nums) {
        if (null==nums|| nums.length == 0 || nums.length == 1) {
            return 0;
        }
        int currDis = 0;
        int maxDis = 0;
        int count=0;
        for (int i = 0; i < nums.length; i++) {
            maxDis = Math.max(maxDis, i + nums[i]);

            if (maxDis >= nums.length - 1) {
                count++;
                break;
            }

            //如果达到了currDis,需要更新
            if (i == currDis) {
                currDis=maxDis;
                count++;
            }
        }
        return count;
    }
}